import java.util.Stack;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 05 - 27
 * Time: 10:15
 */
class Solution {
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for(int i = 0; i < tokens.length; i++) {
            String string = tokens[i];
            if(isNumber(string) == true) {
                stack.push(Integer.parseInt(string));
            }else {
                int num2 = stack.pop();
                int num1 = stack.pop();
                switch(string){
                    case("+"):
                        stack.push(num1 + num2);
                        break;
                    case("-"):
                        stack.push(num1 - num2);
                        break;
                    case("*"):
                        stack.push(num1 * num2);
                        break;
                    case("/"):
                        stack.push(num1 / num2);
                        break;
                }
            }
        }
        return stack.pop();
    }
    private boolean isNumber(String string) {
        if((string.equals("+")) || (string.equals("-")) || (string.equals("*")) || (string.equals("/"))) {
            return false;
        }else {
            return true;
        }
    }
}
